﻿using FanaticUnitity.FfmpegZoomPictureTo300KB.Models;
using System;

namespace FanaticUnitity.FfmpegZoomPictureTo300KB.Helpers
{
    internal static class ImageHelper
    {
        public static Image Convert300KbImage(Image image)
        {
            if (image.Length < FileHelper.SizeSmallKB) return image;
            var powratio = 1d * FileHelper.SizeSmallKB / image.Length * 0.8;
            var ratio = Math.Sqrt(powratio);
            var newSize = image.Size * ratio;

            return new Image() { Size = newSize, Length = newSize.Area };
        }
    }
}
